package com.application.fabric.users.config.HDFS;

import lombok.extern.slf4j.Slf4j;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.stereotype.Repository;

@Repository
public class HDFSConfiguration {

//配置文件读取指
    private static String user = "hatelys";
    private static String password = "123456";
    private static String hdfsSite = "/home/hatelys/HDFS/hadoop-3.2.2/etc/hadoop/hdfs-site.xml";
    private static String coreSite = "/home/hatelys/HDFS/hadoop-3.2.2/etc/hadoop/core-site.xml";

    public FileSystem createFs() throws Exception {
        System.setProperty("HADOOP_USER_NAME", user);
        System.setProperty("HADOOP_USER_PASSWORD", password);
        Configuration conf = new Configuration();
        System.setProperty("HADOOP_HOME","/home/hatelys/HDFS/hadoop-3.2.2");
        System.setProperty("hadoop.home.dir","/home/hatelys/HDFS/hadoop-3.2.2");
        conf.set("fs.defaultFS", "hdfs://localhost:9000"); // 设置HDFS的URL
        conf.addResource(coreSite);
        conf.addResource(hdfsSite);

        FileSystem fs = FileSystem.get(conf);
        return fs;
    }

}
